import { getUsers,getDept ,getRole,getMenu,getMenuById} from "../apis/system";

export default{
    state:{
        users:null,
        dept:null,
        role:null,
        menu:null,
        menuId:null
       
    },
    effects:{
        *getUsersBySaga({data},{put,call}){
            // console.log('参数',data);
       const res=yield call(getUsers,data)
       console.log(res);
    //    yield put({type:"initUsers",payload:res.rows})
    yield put({type:"initUsers",payload:res})
        },
        *getDeptBySaga({data},{put,call}){
          const res=yield call(getDept)
        //   console.log('部门',res);
          yield put({type:"initDept",payload:res.rows.children})
        },
        *getRoleBySaga({data},{put,call}){
            const res=yield call(getRole,data)
        console.log('角色',res);
        yield put({type:"initRole",payload:res})
        },
        *getMenuBySaga({data},{put,call}){
            const res=yield call(getMenu,data)
            console.log("菜单",res);
        yield put({type:'initMenu',payload:res.rows.children})
        },
        *getMenuIdBySaga({id},{put,call}){
            // console.log(id);
        const res=yield call(getMenuById,id)
        console.log("根据角色获取菜单",res);
        yield put ({type:'initMenuId',payload:res})
        }
    },
    reducers:{
        initUsers(state,action){
            state.users=action.payload
        },
        initDept(state,action){
            state.dept=action.payload
        },
        initRole(state,action){
            state.role=action.payload
        },
        initMenu(state,action){
            state.menu=action.payload
        },
        initMenuId(state,action){
            state.menuId=action.payload
        }
    }
}
